<?php
/**
 * 余额提现
**/
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
$title='余额提现';
include_once './header.php';
if(file_exists(ROOT.'assets/img/skimg/sk_'.$userrow['uid'].'.png')){
    $skimg = '../assets/img/skimg/sk_'.$userrow['uid'].'.png';
}else{
    $skimg = '../assets/img/skimg/sk.png';
}
?>
<?php
if($conf['user_tixian']!=1)showmsg('错误', '授权平台未开放提现功能！', 4, './');
function display_zt($zt){
    if($zt==2)
        return '<a class="layui-btn layui-btn-xs" onclick="layer.msg(\'提现审核未通过,请检查提现信息是否正确!\')" style="background-color: rgba(14,0,101,0.6)"><font color="white">已退款</font></a>';
    elseif($zt==1)
        return '<a class="layui-btn layui-btn-xs" onclick="layer.msg(\'提现审核通过,已帮您提现至指定账户,有任何问题请联系客服处理\')" style="background-color: #00cb5b"><font color="white">已完成</font></a>';
    else
        return '<a class="layui-btn layui-btn-xs" onclick="layer.msg(\'请等待提现处理完成!\')" style="background-color: #5c3dff"><font color="white">待处理</font></a>';
}
function display_type($type){
    if($type==1)
        return '<font color=#E65100>微信</font>';
    elseif($type==2)
        return '<font color=#43A047>QQ钱包</font>';
    else
        return '<font color=#BA68C8>支付宝</font>';
}
$tixian=$DB->get_row("select * from authguao_tixian where uid='{$userrow['uid']}' order by addtime desc limit 1");
$count=$DB->count("SELECT sum(money) FROM authguao_tixian WHERE uid='{$userrow['uid']}' AND status=3");
$count2=$DB->count("SELECT sum(money) FROM authguao_tixian WHERE uid='{$userrow['uid']}'");
$count3=$DB->count("SELECT sum(money) FROM authguao_tixian WHERE uid='{$userrow['uid']}' AND status=1");
$numrows=$DB->count("SELECT count(*) from authguao_tixian WHERE uid='{$userrow['uid']}'");
$url = 'https://api.fcypay.com/';
$m = md5(rand(1000000,9999999).date('YmdHis').uniqid());
$code_url = $url.'get_openid_qrcode?mark='.$m;
$cron_url = $url.'get_openid_status?mark='.$m;
?>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                <input type="file" id="file" onchange="fileUpload()" style="display:none;"/>
                提现申请 - <span class="badge badge-success-lighten" onclick="layer.alert('<img src='+$('#GatheringFigure').attr('src')+' width=300 heigth=300/>')" id="GatheringFigure" src="<?php echo $skimg ?>">查看收款二维码</span> <a href="javascript:fileSelect()" class="badge badge-danger-lighten">上传新的收款二维码</a>
            </div>
            <div class="card-body">
                <form class="form-horizontal layui-form">
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">提现方式：<span class="badge badge-danger-lighten">手续费：<?php echo (100-$conf['tixian_rate'])?>%</span> <span class="badge badge-primary-lighten">单笔<?php echo $conf['tixian_min'] ?>元起提，最高<?php echo $conf['tixian_max'] ?>元</span></label>
                        <select class="form-control" name="type" default="<?php echo $tixian['type']?>"><option value="0">支付宝</option><option value="1">微信</option><option value="2">QQ钱包</option></select>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">收款人姓名：</label>
                        <input type="text" name="name" value="<?php echo $tixian['name']; ?>" class="form-control" placeholder="请填写收款人姓名" lay-verType="tips" lay-verify="required"/>
                     </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">提现账号：<a href="javascript:getopenid()" class="badge badge-danger-lighten" style="display:none" id="getopenid">自动获取</a></label>
                        <input type="text" name="account" value="<?php echo $tixian['account']; ?>" class="form-control" placeholder="请填写提现账号" lay-verType="tips" lay-verify="required"/>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">提现备注：</label>
                        <input type="text" name="remarks" class="form-control" placeholder="管理员会看到,可填可不填"/>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">提现金额：<span class="badge badge-danger-lighten">可提现余额：<?php echo round($userrow['rmb_tc'],2)?>元</span> <span class="badge badge-primary-lighten">不可提现余额：<?php echo round($userrow['rmb'],2) ?>元</span></label>
                        <input type="number" name="money" value="<?php echo $conf['tixian_min'] ?>" class="form-control" placeholder="输入要提现的金额"/>
                    </div>
                    <button type="submit" class="btn btn-block btn-xs btn-outline-success" lay-submit lay-filter="submit_tixian">申请提现</button>
                </form>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                提现记录
                <span class="badge badge-primary-lighten">待处理(<?php echo round($count,2)?>元)</span>
                <span class="badge badge-warning-lighten">累计提现(<?php echo round($count2,2)?>元) </span>
                <span class="badge badge-success-lighten">成功提现(<?php echo round($count3,2)?>元)</span>
            </div>
            <div class="card-body">
                <div style="white-space:nowrap;overflow-x: auto;">
                    <table class="layui-table layuiadmin-page-table">
                        <thead><tr><th>ID</th><th>提现金额</th><th>实际到账</th><th>提现状态</th><th>提现备注</th><th>收款方式</th><th>收款姓名</th><th>收款账号</th><th>处理时间</th><th>提现时间</th></tr></thead>
                        <tbody>
                        <?php
                        $pagesize=30;
                        $pages=ceil($numrows/$pagesize);
                        $page=isset($_GET['page'])?intval($_GET['page']):1;
                        $offset=$pagesize*($page - 1);
                        $rs=$DB->query("SELECT * FROM authguao_tixian WHERE uid='{$userrow['uid']}' ORDER BY id DESC LIMIT $offset,$pagesize");
                        while($res = $DB->fetch($rs))
                        {
                        echo '<tr><td><b>'.$res['id'].'</b></td><td style="color:#4E342E">'.$res['money'].'</td><td style="color:#FB8C00">'.$res['realmoney'].'</td><td>'.display_zt($res['status']).'</td><td>'.$res['remarks'].'</td><td>'.display_type($res['type']).'</td><td>'.$res['name'].'</td><td>'.$res['account'].'</td><td>'.($res['status']>=1?$res['endtime']:'尚未处理，请耐心等待').'</td><td>'.$res['addtime'].'</td></tr>';
                        }
                        ?>
                        </tbody>
                    </table>
                </div>
                <div class="text-center">
                <?php
                #分页
                $pageList=new Page($numrows,$pagesize,0,$link);
                echo $pageList->showPage();
                ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script src="//lib.baomitu.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<script type="text/javascript">
layui.use(['form'], function () {
    var form = layui.form;
    form.on('submit(submit_tixian)', function (data) {
        layer.alert('是否要执行当前操作？', {
            icon: 3, btn: ['确定', '取消'], btn1: function (layero, index) {
                tixian();
            }
        });
        return false;
    });
});
function fileSelect(){
    $("#file").trigger("click");
}
function fileUpload(){
    var fileObj = $("#file")[0].files[0];
    if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
        return;
    }
    var formData = new FormData();
    formData.append("do","skimg");
    formData.append("shoukuan",fileObj);
    var ii = layer.msg('正在上传图片中,请稍后...', {icon: 16, time: 10 * 1000});
    $.ajax({
        url: "ajax.php?act=uploadskimg",
        data: formData,
        type: "POST",
        dataType: "json",
        cache: false,
        processData: false,
        contentType: false,
        success: function (data) {
            layer.close(ii);
            if(data.code == 0){
                layer.msg('上传图片成功', {icon: 6});
            }else{
                layer.msg(data.msg, {icon: 5});
            }
        },
        error:function(data){
            layer.msg('服务器错误', {icon: 5});
            return false;
        }
    })
}
function tixian() {
    var type = $("select[name='type']").val();
    var name = $("input[name='name']").val();
    var account = $("input[name='account']").val();
    var remarks = $("input[name='remarks']").val();
    var money = $("input[name='money']").val();
    if(money=='' || money==0){layer.msg('充值金额不能为空', {icon: 5});return false;}
    var ii = layer.msg('正在提交中,请稍后...', {icon: 16, time: 10 * 1000});
    $.ajax({
        type: "POST",
        url: "ajax.php?act=tixian",
        data : {type:type,name:name,account:account,remarks:remarks,money:money},
        dataType: "json",
        success: function(data) {
            layer.close(ii);
            if (data.code == 0) {
                layer.msg(data.msg, {icon: 6});
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        },
        error:function(data){
            layer.msg('服务器错误', {icon: 5});
            return false;
        }
    });
    return false;
};
<?php if($conf['user_daifu']==1){?>
var getopenid = function () {
    var open = layer.open({
        type:1,
        title:'',
        content:'<div class="layui-card-body"><h3 style="text-align:center">请使用微信扫一扫</h3><div><div id="qrcode" style="padding:15px;"></div></div></div>',
        cancel: function(index, layero){ 
            layer.close(open);
            window.clearInterval(cron); 
        },success: function(){ 
            var code_url = '<?php echo $code_url?>';
            $('#qrcode').qrcode({
                text: code_url,
                width: 230,
                height: 230,
                foreground: "#000000",
                background: "#ffffff",
                typeNumber: -1
            });
        }
    });
    var cron = setInterval(function(){
        $.ajax({
            type: "GET",
            url: '<?php echo $cron_url;?>'+'&r='+Math.random(),
            dataType: "json",
            success: function(data){
                if (data.code) {
                    $("input[name=account]").val(data.data);
                    layer.close(open);
                    window.clearInterval(cron); 
                }
            }
        });
    },3000);
}
$("select[name='type']").change(function(){
    if($(this).val() == 1){
        $("#getopenid").show();
        $("input[name=account]").attr("readOnly","readOnly");
    }else{
        $("#getopenid").hide();
        $("input[name=account]").removeAttr("readOnly");
    }
});
$("select[name='type']").change();
<?php }?>
</script>